
var height = $(document.body).height()+"px";
//用react封装
var currentpage = 1,totlepage = 1,i;//分页的当前页和总的页数
//表单数据：学校页面的对应注解：学校名称 考勤区域  隶属地区 设备自定义套餐（扩展）学校id
var schoolData = [],schoolDataAll = [],schoolDataList = [];
//学校页面弹出层 数据
var schoolPopData = {};
//表单的最高高度、当前第几页、总页数、总行数、设备投放切换、箱号
var otherData = {maxHeight:'0px',currentpage:0,totlepage:0,totlerows:0,pageLeft:0,pageRight:0,view:'',boxOrdevice:'device',batchNumber:'',upBatchNumber:''};
var title="新增";
var Page = React.createClass({
    setPage: function (e) {
        setPage($(e.target).html());
        this.props.onPageClick(1);
    },
    showPage: function () {
        showPage();
    },
    render: function () {
        {
            var items = [],
                svar = this;
            if(totlepage == 0 ){
                items.push({num:1,checked:true})
            }else if(totlepage < 6){
                for(i = 1;i <= totlepage ;i++) {
                    if (i == currentpage) {
                        items.push({num:i,checked:true})
                    } else {
                        items.push({num:i,checked:false})
                    }
                }
            }else if(currentpage >= (totlepage-2)) {//点在左边
                items.push({num:1,checked:false});
                items.push({num:'···',checked:false});
                for(i = totlepage-2;i <= totlepage ;i++){
                    if(i == currentpage){
                        items.push({num:i,checked:true})
                    }else{
                        items.push({num:i,checked:false})
                    }
                }
            }else if(currentpage <= 3){
                for(i = 1;i <= 3 ;i++) {
                    if (i == currentpage) {
                        items.push({num:i,checked:true})
                    } else {
                        items.push({num:i,checked:false})
                    }
                }
                items.push({num:'···',checked:false});
                items.push({num:totlepage,checked:false})
            }else {//点在两边
                items.push({num:1,checked:false});
                items.push({num:'···',checked:false});
                items.push({num:currentpage-1,checked:false});
                items.push({num:currentpage,checked:true});
                items.push({num:currentpage+1,checked:false});
                items.push({num:'···',checked:false});
                items.push({num:totlepage,checked:false})
            }
        }
        return (
            <div className="tableInfo-page">
                <div className="page-number">每页<span className="page-number-list" onClick={this.showPage}>{pagecount}</span>条</div>
                <div className="page-list" style={{top:pageListTop+"px"}}>
                    <ul>
                        {
                            pageList.map(function (item) {
                                return (<li onClick={svar.setPage}>{item}</li>)
                            })
                        }
                    </ul>
                </div>
                <div className="page-limit">
                    <ol className="page-limit-ol">
                        <ol className="page-limit-ol">
                            <li className="page-limit-img" name="-1" onClick={otherData.pageLeft == 0?'':svar.props.onPageClick.bind(svar,-1)} ><span className={otherData.pageLeft == 0?'page-limit-left-no':'page-limit-left-yes'}/></li>
                            {
                                items.map(function (item) {
                                    return (<li onClick={isNaN(item.num)?'':svar.props.onPageClick.bind(svar,item.num)} className={item.checked == true?'page-limit-num page-limit-checked':'page-limit-num'} name={item.num}>{item.num}</li>)
                                })
                            }
                            <li className="page-limit-img" name="-2" onClick={otherData.pageRight == 0?'':svar.props.onPageClick.bind(svar,-2)} ><span className={otherData.pageRight == 0?'page-limit-right-no':'page-limit-right-yes'}/></li>
                        </ol>
                    </ol>
                </div>
            </div>
        );
    },
});
//分页
//表单组件
var TableSchool = React.createClass({
    render: function () {
        return (
            <tr>
                <td style={{width: '8%'}}>{parseInt(this.props.listNumber)+1}</td>
                <td style={{width: '20%'}}>{this.props.schoolname}</td>
                <td style={{width: '20%'}}>{this.props.showtimesetting}</td>
                <td style={{width: '15%'}}>{this.props.yijiaoid}</td>
                <td style={{width: '20%'}}>{this.props.address}</td>
                {/*<td style={{width: '13%'}}>{this.props.starttime != ""?this.props.starttime+"至"+this.props.endtime:""}</td>*/}
                {/*<td style={{width: '10%'}}>{this.props.price== null?"":parseFloat(this.props.price).toFixed(2)}</td>*/}
                <td style={{width: '15%'}}>
                    <div onClick={this.props.onClickTableUpdate}  className="trButton trLeft">修改</div>
                    <div onClick={this.props.onClickTableDelete} className="trButton resetPwd trLeft">删除</div>
                </td>
            </tr>
        );
    }
});
//学校组件
var School = React.createClass({
    onClickQuery: function (schoolDataType) {
        suixun.showLoding();//显示加载中
        var svar = this;
        var param="param={";
        param = getJsonDataNotEmpty(param,"schoolname",$("#schoolname_search").val());
        param = getJsonDataNotEmpty(param,"pagecount",pagecount+'');
        param += "}";
        schoolData = [];
        if(schoolDataType){
            param += '&type=1';
        }
        suixun.ajax(serverUrl+'/schoolManage/querySchoolList.json',param,"get",function(data){
            suixun.hideLoding();//隐藏加载中
            if(data.code == 200){
                for(var i=0;i<data.info.queryresult.length;i++){
                    var obj=data.info.queryresult[i];
                    schoolData[i] = {id:obj.id,timeSettingid:obj.timeSettingid,province:obj.province,city:obj.city,town:obj.town,schoolname:obj.schoolname,dis:obj.dis,showtimesetting:obj.showtimesetting,address:obj.address,yijiaoid:obj.yijiaoid,starttime:obj.starttime,endtime:obj.endtime,price:obj.price,schooltype:obj.schooltype};
                }
                var pageRight = 0;
                if(data.info.totlepage > 1){
                    pageRight = 1
                }
                otherData = {maxHeight:height,currentpage:1,totlepage:data.info.totlepage,totlerows:data.info.totlerows,pageLeft:0,pageRight:pageRight,view:'school',batchNumber:'',upBatchNumber:''};
                currentpage = 1;totlepage = data.info.totlepage;//初始化的时候赋值：分页的当前页和总的页数
                svar.setState({schoolData:schoolData,otherData:otherData});
            }
        });
    },
    onPageClick: function (num) {
        //分页-调用ajac然后把数据查询出来:获取name的值
        //计算currentpage
        suixun.showLoding();//显示加载中
        var onPageLeft = 0,onPageRight = 1,svar = this;
        if(num > 0){
            currentpage = num;
        }else if(num == -1 && currentpage > 1){
            currentpage --;
        }else if(num == -2  && currentpage < totlepage){
            currentpage ++;
        }
        //修改左右的按钮
        if((currentpage == totlepage && totlepage == 1)|| totlepage == 0){
            onPageLeft = 0;
            onPageRight = 0;
        }else if(currentpage == totlepage && totlepage > 1){
            onPageLeft = 1;
            onPageRight = 0;
        }else if(1 < currentpage && currentpage < totlepage){
            onPageLeft = 1;
            onPageRight = 1;
        }

        var param="param={pagenumber:"+currentpage+",pagecount:"+pagecount;
        param = getJsonDataNotEmpty(param,"schoolname",$("#schoolname_search").val());
        param += "}";
        schoolData = [];
        if(this.props.schoolDataType){
            param += '&type=1';
        }
        //执行ajax获取数据然后组装
        suixun.ajax(serverUrl+'/schoolManage/querySchoolList.json',param,"get",function(data){
            suixun.hideLoding();//隐藏加载中
            if(data.code == 200){
                for(var i=0;i<data.info.queryresult.length;i++){
                    var obj=data.info.queryresult[i];
                    schoolData[i] = {id:obj.id,timeSettingid:obj.timeSettingid,province:obj.province,city:obj.city,town:obj.town,schoolname:obj.schoolname,dis:obj.dis,showtimesetting:obj.showtimesetting,address:obj.address,yijiaoid:obj.yijiaoid,starttime:obj.starttime,endtime:obj.endtime,price:obj.price,schooltype:obj.schooltype};
                }
                if(data.info.totlepage > 1 && data.info.totlepage > currentpage){
                    onPageRight = 1
                }else{
                    onPageRight = 0;
                }
                totlepage = data.info.totlepage;
                otherData = {maxHeight:height,currentpage:currentpage,totlepage:data.info.totlepage,totlerows:data.info.totlerows,pageLeft:onPageLeft,pageRight:onPageRight,view:'school',batchNumber:'',upBatchNumber:''};
                svar.setState({schoolData:schoolData,otherData:otherData});
            }
        });
    },
    //隐藏pop
    onClickHidePop: function () {
        $(".initializeMenu", window.parent.document).hide();//父页面的遮罩
        $(".schoolPop").hide();
        $(".errorMsg").hide();
        $("#province").find(".pop-address-content-default").html('选择省份');
        $("#city").find(".pop-address-content-default").html('选择地区');
        $("#county").find(".pop-address-content-default").html('选择县或街道');
        $("#pop-schoolName").val('');//学校名称
        $("#yijiaoid").val('');//壹教云id
        $("#schoolAddress").val('');//学校地址
        $("#starttime").val('');//促销活动开始时间
        $("#endtime").val('');//促销活动结束时间
        $("#promoPrice").val('');//促销价格
        $(".time-father").html("");//考勤区间
        this.props.changgePopSchoolDataType(false);
    },
    getInitialState:function () {
        return{
            schoolid:''
        }
    },
    /**
     * 表单修改按钮
     * @param info
     */
    onClickTableUpdate: function (info) {
        //组装考勤区间
        suixun.showLoding();//显示加载中
        var showtimesettings = info[5].split(" ");
        for(var i = 0;i < showtimesettings.length;i++){
            if(showtimesettings[i] == ""){
                continue;
            }
            $(".time-father").append('' +
                '<span class="time-array">' +
                '<span class="pop-body-input-content" >' +
                ' <input size="16" style="margin-top: 0px" class="input-content inputTime timeMapFirst" type="text" placeholder="选择时间" value="'+showtimesettings[i].split("-")[0]+'"  />' +
                '</span>' +
                '<span class="pop-body-input-content timeRight" >' +
                '<input size="16" style="margin-top: 0px"  class="input-content inputTime timeMapLast" data-ids="id" type="text" placeholder="选择时间" value="'+showtimesettings[i].split("-")[1]+'"  />' +
                '<img class="schoolDeleteTime" data-value="id" src="../img/icon/delete.png" />' +
                '</span>' +
                '</span>');
            $('.inputTime').datetimepicker({
                datepicker:false,//关闭日期选项
                format:'H:i',//格式化日期
                step:5//时间间隔
            });
        }
        if(info[12] != null){
            $("#timeSettingid").val(info[12]);//考勤区间id
        }else{
            $("#timeSettingid").val("");
        }
        schoolPopData = {title:'修改学校'};
        this.setState({schoolPopData:schoolPopData,schoolid:info[0]});
        var param="param={";
        param = getJsonDataNotEmpty(param,"schoolname",info[1]);
        param += "}";
        suixun.ajax(serverUrl+'/schoolManage/querySchool.json',param,"get",function(data){
            suixun.hideLoding(200);//隐藏加载中
            if(data.code == 200){
                //学校没有关联省市区
                $(".popPhone").css("display","block");
                $("#pop-schoolName").val(info[1]);//学校名称
                $('#schoolAddress').val(info[2]);//学校地址
                $('#yijiaoid').val(info[3]);//学校地址
                $('#starttime').val(info[6]);//促销活动开始时间
                $('#endtime').val(info[7]);//促销结束时间
                $('#promoPrice').val(info[8]==null?"":(parseFloat(info[8])).toFixed(2));//促销金额
                if(data.info[0].province == null){
                    $(".span-provinceid").html("选择省份").attr("title","选择省份");
                    $(".span-cityid").html("选择地区").attr("title","选择地区");
                    $(".span-countyid").html("选择县或街道").attr("title","选择县或街道");
                    $("#provinceid").val("");
                    $("#cityid").val("");
                    $("#countyid").val("");//省市区
                }else{
                    $(".span-provinceid").html(data.info[0].province).attr("title",data.info[0].province);
                    $(".span-cityid").html(data.info[0].city).attr("title",data.info[0].city);
                    $(".span-countyid").html(data.info[0].town).attr("title",data.info[0].town);
                    $("#provinceid").val(data.info[0].province);
                    $("#cityid").val(data.info[0].city);
                    $("#countyid").val(data.info[0].town);//省市区
                }
                this.props.changgePopSchoolDataType(info[13]=='1'?true:false);
            }else {
                suixun.alert(data.msg);
            }
        }.bind(this));
    },
    //表单删除按钮
    onClickTableDelete: function (schoolid) {
        var svar = this;
        suixun.confirm_noTit('是否删除？',function (data) {
            if (data) {
                suixun.showLoding();//显示加载中
                var param = "param={";
                param = getJsonDataNotEmpty(param, "schoolid", "\"" + schoolid + "\"");
                param += "}";
                suixun.ajax(serverUrl + '/schoolManage/deleteSchool.json',param,"get",function(data){
                    suixun.hideLoding(200);//隐藏加载中
                    if (data != null && data.code == 200) {
                        suixun.alert("删除成功!",function (data) {
                            if(data){
                                var tbodyData = $("#tbodyData").children();
                                if(tbodyData.length == 1 && currentpage > 1){
                                    totlepage = totlepage - 1;
                                    svar.onPageClick(currentpage-1);//更新数据
                                }else{
                                    svar.onPageClick(currentpage);//更新数据
                                }
                                svar.props.selectSchoolData();//查询学校列表
                            }
                        });
                    } else {
                        suixun.alert(data.msg);
                    }
                });
            }
        });
    },
    //新增学校
    onClickAddSchool: function () {
        schoolPopData = {title:'新增学校'};
        this.setState({schoolPopData:schoolPopData});
        $(".initializeMenu", window.parent.document).show();//父页面的遮罩
        $(".time-father").html("");
        $("#timeSettingid").val("");//考勤区间id设为空
        $(".schoolPop").show();
    },
    //新增时间区间
    onClickaddSchoolTime: function () {
        $(".time-father").append('' +
            '<span class="time-array">' +
            '<span class="pop-body-input-content" >' +
            '<input size="16" style="margin-top: 0px" class="input-content inputTime timeMapFirst" type="text" placeholder="选择时间" value=""  />' +
            '</span>' +
            '<span class="pop-body-input-content timeRight" >' +
            '<input size="16" style="margin-top: 0px"  class="input-content inputTime timeMapLast" type="text" placeholder="选择时间" value=""  />' +
            '<img class="schoolDeleteTime" src="../img/icon/delete.png" />' +
            '</span>' +
            '</span>');
        $('.inputTime').datetimepicker({
            datepicker:false,//关闭日期选项
            format:'H:i',//格式化日期
            step:5//时间间隔
        });

    },
    /**
     * 保存学校
     * @returns {boolean}
     */
    onClockSaveSchool: function () {
        var svar = this,
            schoolName = $('#pop-schoolName').val(),//学校名称
            schoolAddress = $('#schoolAddress').val(),//学校地址
            yijiaoid = $('#yijiaoid').val(),//学校地址
            // starttime = $('#starttime').val(),//促销促销结束时间
            // endtime = $('#endtime').val(),//促销开始时间
            // promoPrice = $('#promoPrice').val(),//促销价格
            // promoType = true,//false 没有促销活动，true有促销活动
            provinceid =  $(".span-provinceid").html(),//省
            cityid = $(".span-cityid").html(),//市
            countyid = $(".span-countyid").html();//区
        if(schoolName == ""){
            suixun.alert("学校名称不能为空!");
            $(".schoolName-error").show();
            return;
        }
        if(schoolAddress == ""){
            suixun.alert("学校地址不能为空!");
            $(".schoolAddress-error").show();
            return;
        }
        if(yijiaoid == ""){
            suixun.alert("壹教云ID不能为空!");
            $(".yijiaoid-error").show();
            return;
        }
        if(schoolPopData.title=="修改学校"){
            if(provinceid != "选择省份" ){
                if(cityid == "选择地区" ){
                    suixun.alert("选择地区");
                    return;
                }else{
                    if(countyid == "选择县或街道" ){
                        suixun.alert("选择县或街道");
                        return;
                    }
                }
            }else{
                provinceid = "";
                cityid = "";
                countyid = "";
            }
        }else{
            if(provinceid == "选择省份" ){
                suixun.alert("选择省份");
                return;
            }
            if(cityid == "选择地区" ){
                suixun.alert("选择地区");
                return;
            }
            if(countyid == "选择县或街道" ){
                suixun.alert("选择县或街道");
                return;
            }
        }
        //促销价格和促销时间必须同时为空
        // if(starttime == "" && endtime == "" && promoPrice == ""){
        //     promoType = false;
        // }else if(starttime != "" && endtime != "" && promoPrice != ""){
        //     if(new Date(starttime.replace(/\-/g, "\/")) >= new Date(endtime.replace(/\-/g, "\/"))){
        //         suixun.alert("促销开始时间不能促销大于结束时间！");
        //         return false;
        //     }else{
        //         starttime += " 00:00:00";
        //         endtime += " 23:59:59";
        //     }
        //     if(!/(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/.test(promoPrice) && !/(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\?$)/.test(promoPrice)){
        //         suixun.alert("促销金额格式错误！",function (data) {
        //             if(data){
        //                 $('#promoPrice').val("");
        //             }
        //         });
        //         return false;
        //     }else{
        //         promoPrice = parseFloat(promoPrice).toFixed(2);
        //         promoType = true;
        //     }
        // }else{
        //     if(starttime == "" && endtime != "" && promoPrice != ""){
        //         suixun.alert("促销金额有值时促销开始时间不能为空!");
        //         return;
        //     }else if(starttime != "" && endtime == "" && promoPrice != ""){
        //         suixun.alert("促销金额有值时促销结束时间不能为空!");
        //         return;
        //     }else if(starttime != "" && endtime != "" && promoPrice == ""){
        //         suixun.alert("促销时间有值时促销结束金额不能为空!");
        //         return;
        //     }else if(starttime == "" && endtime == "" && promoPrice != ""){
        //         suixun.alert("促销金额有值时促销开始时间不能为空!");
        //         return;
        //     }else if(starttime == "" && endtime != "" && promoPrice == ""){
        //         suixun.alert("促销结束时间有值时促销开始时间不能为空!");
        //         return;
        //     }else if(starttime != "" && endtime == "" && promoPrice == ""){
        //         suixun.alert("促销开始时间有值时促销结束时间不能为空!");
        //         return;
        //     }
        // }
        var timeLen=$('.timeMapFirst').length;
        var showtimesetting='';
        for(var i=0;i<timeLen;i++){
            var startTime=$('.timeMapFirst').eq(i).val();
            var endTime=$('.timeMapLast').eq(i).val();
            var isId = $('.timeMapLast').eq(i).attr("data-ids");
            if(isId == 'id' && $('.timeMapLast').eq(i).parent().parent().is(":hidden")){
                if(i==timeLen-1){
                    showtimesetting+='';
                }else{
                    showtimesetting+=',';
                }
            }else if(startTime!=""&&endTime!=""){
                if( startTime.substring(0,2)>endTime.substring(0,2)){
                    suixun.alert('考勤区间不符');
                    return false;
                }else if(startTime.substring(0,2)==endTime.substring(0,2)&&startTime.substring(3,5)>endTime.substring(3,5)){
                    suixun.alert('考勤区间不符');
                    return false;
                }
                if(i==timeLen-1){
                    showtimesetting+=startTime+'-'+endTime;
                }else{
                    showtimesetting+=startTime+'-'+endTime+',';
                }
            }
        }
        suixun.showLoding();//显示加载中
        var msg = "新增";
        var saveUrl='/schoolManage/addSchool.json';
        var param="param={";
        param = getJsonDataNotEmpty(param,"schoolname", '"'+$('#pop-schoolName').val()+'"');
        if(schoolPopData.title == "修改学校"){
            param = getJsonDataNotEmpty(param,"id",'"'+this.state.schoolid+'"');
            saveUrl='/schoolManage/modifySchool.json';
            msg = "修改";
        }
        param = getJsonDataNotEmpty(param,"address",'"'+$('#schoolAddress').val()+'"');
        param = getJsonDataNotEmpty(param,"yijiaoid",'"'+$('#yijiaoid').val()+'"');
        param = getJsonDataNotEmpty(param,"province","\""+provinceid+"\"");
        param = getJsonDataNotEmpty(param,"city","\""+cityid+"\"");
        param = getJsonDataNotEmpty(param,"timeSettingid","\""+$("#timeSettingid").val()+"\"");
        param = getJsonDataNotEmpty(param,"town","\""+countyid+"\"");
        param = getJsonDataNotEmpty(param,"showtimesetting",'"'+showtimesetting+'"');
        // if(promoType){
        //     param = getJsonDataNotEmpty(param,"starttime",'"'+starttime+'"');
        //     param = getJsonDataNotEmpty(param,"endtime",'"'+endtime+'"');
        //     param = getJsonDataNotEmpty(param,"price",'"'+promoPrice+'"');
        // }
        param += "}";
        if(this.props.popSchoolDataType){
            param += '&schooltype=1';
        }
        suixun.ajax(serverUrl+saveUrl,param,"get",function(data){
            suixun.hideLoding(200);//隐藏加载中
            if(data!=null && data.code == 200){
                if(schoolPopData.title=="修改学校"){
                    suixun.alert(msg+"成功!",function (data) {
                        if(data){
                            svar.onPageClick(currentpage);
                            svar.onClickHidePop();
                            svar.props.selectSchoolData();
                        }
                    });
                    svar.setState({schoolid:''});
                }else{
                    suixun.alert(msg+'成功!',function (data) {
                        if(data){
                            svar.onClickHidePop();
                            svar.onPageClick(currentpage);
                            svar.props.selectSchoolData();
                        }
                    });
                }
            } else {
                suixun.alert(data.msg);
            }
        });
    },
    //excel导出
    onClickExport: function () {
        suixun.confirm_noTit("是否确定导出Excel？",function (data) {
            if(data){
                var param="param={";
                param = getJsonDataNotEmpty(param,"schoolname",$("#schoolname_search").val());
                param = getJsonDataNotEmpty(param,"pagenumber",""+otherData.currentpage+"");
                param = getJsonDataNotEmpty(param,"pagecount",pagecount+'');
                param += "}";
                window.location.href = serverUrl+'/schoolManage/export_SchoolList.json?'+param;
            }
        });
    },
    //验证
    onBlurInput: function (e) {
        var classname = e.target.getAttribute("data-error");
        if($(e.target).val() == ''){
            $("."+classname+"").show();
        }else{
            $("."+classname+"").hide();
        }
    },
    //改变弹出层学校输入框
    onChangSchoolInput: function (e) {
        var val = $(e.target).val();
        if(val != ""){
            this.schoolArray(val,$(e.target).attr("data-list"));
        }else{
            $("."+$(e.target).attr("data-list")+"").hide();
        }
    },
    //排序
    schoolArray: function (val,cls) {
        schoolDataList = [];
        for(var i = 0;i < schoolDataAll.length;i++){
            if((schoolDataAll[i].schoolname).indexOf(val) >= 0){
                schoolDataList.push({schoolname:schoolDataAll[i].schoolname});
            }
        }
        if(schoolDataList.length == 0){
            $("."+cls+"").hide();
        }else{
            $("."+cls+"").show();
            this.setState({schoolDataList:schoolDataList});
        }
    },
    //点击学校输入框
    onClickSchool: function (e) {
        var val = $(e.target).val();
        this.schoolArray(val,$(e.target).attr("data-list"));
    },
    /**
     * 验证输入框的长度
     * @returns {XML}
     */
    onInputNumber:function (e) {
        var value = e.target.value;
        if(value.length > $(e.target).attr("maxLength")){
            $(e.target).val(value.slice(0,$(e.target).attr("maxLength")));
        }
    },
    /**
     *点击搜索学校的下拉框内容
     *
     */
    onClickQuerySchool: function (e) {
        $("#schoolname_search").val($(e.target).html());
        this.onClickQuery(this.props.schoolDataType);
    },
    render: function () {
        {
            var svar = this;
            var onClickArray = [this.onClickTableUpdate,this.onClickTableDelete];
            var Tabels = schoolData.map(function (data,index) {
                return (
                    <TableSchool key={data.id} province={data.province} city={data.city} town={data.town} listNumber={index} starttime={data.starttime==null?"":(data.starttime).substring(0,11)} endtime={data.endtime==null?"":(data.endtime).substring(0,11)} price = {data.price} schoolname={data.schoolname} yijiaoid={data.yijiaoid} showtimesetting={data.showtimesetting} address={data.address} dis={data.dis} onClickTableUpdate={onClickArray[0].bind(svar,[data.id,data.schoolname,data.address,data.yijiaoid,data.dis,data.showtimesetting,data.starttime==null?"":(data.starttime).substring(0,10),data.endtime==null?"":(data.endtime).substring(0,10),data.price,data.province,data.city,data.town,data.timeSettingid,data.schooltype])}  onClickTableDelete={onClickArray[1].bind(svar,data.id)}  />
                )
            })
        }
        return (
            <div>
                <div className="pop popPhone schoolPop popModel pop-querySchoolList">
                    <div className="model"></div>
                    <div className="pop-info popPhone-info popModel-info">
                        <div className="pop-title popModel-title">
                            <span className="pop-title-content popModel-title-content">
                                <span className="popModel-title-content-solid-left"/>
                                {schoolPopData.title}
                                <span className="popModel-title-content-solid-right"/>
                            </span>
                            <span className="pop-title-img popModel-title-img" onClick={this.onClickHidePop}><img src="../img/icon/close.png" alt="关闭"/></span>
                        </div>
                        <div className="pop-body popModel-body">
                            <input type="hidden" id="timeSettingid"/>
                            <div className="popModel-body-input">
                                <span className="popModel-body-input-title">学校名称</span>
                                <span className="popModel-body-input-content">
                                    {
                                        schoolPopData.title=="新增学校"?
                                            <input className="input-content school" onBlur={this.onBlurInput} id="pop-schoolName" data-error="schoolName-error" maxLength="50" type="text" placeholder="请输入学校名称"/>
                                            :
                                            <input className="input-content school " onBlur={this.onBlurInput} onChange={this.onChangSchoolInput} onClick={this.onClickSchool} data-list="pop-schoolName"  id="pop-schoolName" data-error="schoolName-error" maxLength="50" type="text" placeholder="请输入学校名称"/>
                                    }
                                </span>
                                <div className="errorMsg schoolName-error" ></div>
                                <div className="schoolList pop-schoolName" data-inputId="pop-schoolName" style={{width:"278px"}}>
                                    {
                                        schoolDataList.map(function (data) {
                                            return (
                                                <span className="schoolList-value">{data.schoolname}</span>
                                            )
                                        })
                                    }
                                </div>
                            </div>
                            <div className="popModel-body-input">
                                <span className="popModel-body-input-title">学校地址</span>
                                <span className="popModel-body-input-content">
                                    <input className="input-content " id="schoolAddress"  data-error="schoolAddress-error" onBlur={this.onBlurInput} type="text" maxLength="50"  placeholder="请输入学校地址" />
                                </span>
                                <div className="errorMsg schoolAddress-error" ></div>
                            </div>
                            <div className="popModel-body-input">
                                <span className="popModel-body-input-title">壹教云ID</span>
                                <span className="popModel-body-input-content">
                                    <input className="input-content " id="yijiaoid"  data-error="yijiaoid-error" onBlur={this.onBlurInput} type="text" maxLength="11"  placeholder="请输入壹教云ID" />
                                </span>
                                <div className="errorMsg yijiaoid-error" ></div>
                            </div>
                            <Address/>
                            {/*<div className="popModel-body-input">*/}
                                {/*<span className="popModel-body-input-title" style={{backgroundImage: "url()"}}>促销时间</span>*/}
                                {/*<span className="popModel-body-input-content promoTimeSpan" >*/}
                                    {/*<input className="input-content promoTimeInput" id="starttime" style={{width:"100px"}} type="text" maxLength="20"  placeholder="促销开始时间" />*/}
                                {/*</span>*/}
                                {/*<span className="timer-onle"/>*/}
                                {/*<span className="popModel-body-input-content promoTimeSpan promoTimeSpan-endtime" >*/}
                                    {/*<input className="input-content promoTimeInput" id="endtime" style={{width:"100px"}} type="text" maxLength="20"  placeholder="促销结束时间" />*/}
                                {/*</span>*/}
                            {/*</div>*/}

                            {/*<div className="popModel-body-input">*/}
                                {/*<span className="popModel-body-input-title" style={{backgroundImage: "url()"}}>促销价格</span>*/}
                                {/*<span className="popModel-body-input-content">*/}
                                    {/*<input className="input-content " id="promoPrice" type="text" onInput={this.onInputNumber} maxLength="12"  placeholder="请输入促销价格(保留2位有效数字)" />元*/}
                                {/*</span>*/}
                            {/*</div>*/}
                        </div>
                        <div className="pop-body-input time">
                            <span className="pop-body-input-title" style={{backgroundImage: "url()",margin: "0 -29px 0 29px"}}>考勤区间</span>
                            <div className="time-father">
                                {
                                    /**
                                     * 初始化的时候没有考勤区域
                                     <span className="time-array">
                                     <span className="pop-body-input-content" >
                                     <input size="16" style={{marginTop: "0px"}} className="input-content inputTime timeMapFirst" type="text" onClick={this.onClickTimer} placeholder="选择时间" value=""  />
                                     </span>
                                     <span className="pop-body-input-content timeRight" >
                                     <input size="16" style={{marginTop: "0px"}} className="input-content inputTime timeMapLast" type="text" onClick={this.onClickTimer} placeholder="选择时间" value=""  />
                                     <img className="schoolDeleteTime" src="../img/icon/delete.png" />
                                     </span>
                                     </span>
                                     */
                                }
                            </div>
                        </div>
                        <div className={this.props.popSchoolDataType?'menu-radio-list select':'menu-radio-list '} onClick={this.props.changgePopSchoolDataType.bind(this,!this.props.popSchoolDataType)} ><span>是否为和教育学校</span></div>
                        <div className="addTime" onClick={this.onClickaddSchoolTime}>
                            <img src="../img/icon/add-white.png" />
                            <span>
                                添加考勤区间
                            </span>
                        </div>
                        <div className="popModel-button" onClick={this.onClockSaveSchool}>
                            <span className="popModel-button-ok" >保存</span>
                        </div>
                    </div>
                </div>
                <header>
                    <div className="header-left">
                        <div className="header-left-studentInfo" data-userid="111111">学校列表</div>
                        <div className="menu-radio">
                            <div className={this.props.schoolDataType?'menu-radio-list':'menu-radio-list select'} onClick={this.props.changgeSchoolDataType.bind(this,false)} ><span>全部学校</span></div>
                            <div className={this.props.schoolDataType?'menu-radio-list select':'menu-radio-list'} onClick={this.props.changgeSchoolDataType.bind(this,true)} ><span>和教育学校</span></div>
                        </div>
                        <div className="header-left-annotationsInfo">
                            <img src="../img/icon/annotations.png" />
                            <span className="header-left-annotations-arrowsLeft"/>
                            <div className="header-left-annotations">这里是注释。</div>
                        </div>
                    </div>
                    <div className="header-right">
                        <div className="header-right-query">
                            <div className="header-right-query-input">
                                <input className="queryVal enterEvent" type="text" onChange={this.onChangSchoolInput} onClick={this.onClickSchool} data-list="schoolname_search"  name="schoolname_search" id="schoolname_search" maxLength="50" placeholder="请输入学校关键词"/>
                            </div>
                            <div className="header-right-query-img" onClick={this.onClickQuery.bind(this,this.props.schoolDataType)}></div>
                            <div className="schoolList schoolname_search " data-inputId="schoolname_search">
                                {
                                    schoolDataList.map(function (data) {
                                        return (
                                            <span className="schoolList-value" onClick={svar.onClickQuerySchool}>{data.schoolname}</span>
                                        )
                                    })
                                }
                            </div>
                        </div>
                        <div className="addButton" onClick={this.onClickAddSchool} style={{marginRight:"25px"}}>
                            <span className="addButton-img"><img style={{marginTop:"3px"}} src="../img/icon/add-white.png" /></span>
                            <span className="addButton-text">新增</span>
                        </div>
                        <div className="export" onClick={this.onClickExport}>
                            <span className="export-img"><img src="../img/icon/export.png" /></span>
                            <span className="export-text">导出excel</span>
                        </div>
                    </div>
                </header>
                <div className="tableInfo">
                    <div className="studentsInfo-data tableInfo-data">
                        <div className="studentsInfo-data-table tableInfo-data-table" >
                            <table className="head-body head-body">
                                <thead>
                                    <th style={{width: '8%'}}>序号</th>
                                    <th style={{width: '20%'}}>学校名称</th>
                                    <th style={{width: '20%'}}>考勤区间</th>
                                    <th style={{width: '15%'}}>壹教云ID</th>
                                    <th style={{width: '20%'}}>隶属地址</th>
                                    {/*<th style={{width: '13%'}}>促销时间</th>*/}
                                    {/*<th style={{width: '10%'}}>促销价格</th>*/}
                                    <th style={{width: '15%'}}>设置</th>
                                </thead>
                                <tbody id="tbodyData">
                                    {schoolData==""?'':Tabels}
                                </tbody>
                            </table>
                            {schoolData==""?<div className="tableNoData">{tableNoDataCount}</div>:''}
                        </div>
                    </div>
                    <Page otherData={otherData} onPageClick={this.onPageClick} />
                </div>
                <footer id="copyright">
                    <span><img src="../img/icon/copyright.png"/>{copyright}</span>
                </footer>
            </div>
        );
    }
});
/**
 * 获取行政区域组件开始
 * @type {*}
 */
var Address=React.createClass({
    getInitialState:function () {
        return{
            provinceData:[],
            cityData:[],
            countyData:[]
        };
    },
    queryAddress:function (num,province,city) {
        var param="param={";
        param = getJsonDataNotEmpty(param,"type",'"'+num+'"');
        param = getJsonDataNotEmpty(param,"province",'"'+province+'"');
        param = getJsonDataNotEmpty(param,"city",'"'+city+'"');
        param += "}";
        var svar = this;
        suixun.ajax(serverUrl+'/schoolManage/queryRegion.json',param,"get",function(data){
            if(data.code == 200){
                if(num == "1"){
                    var provinceData = [];
                    for(var i = 0 ;i < data.info.length;i++ ){
                        provinceData[i] = {value:data.info[i].province};
                    }
                    svar.setState({provinceData:provinceData});
                }else if(num == "2"){
                    var cityData = [];
                    for(var i = 0 ;i < data.info.length;i++ ){
                        cityData[i] = {value:data.info[i].city};
                    }
                    svar.setState({cityData:cityData});
                }else{
                    var countyData = [];
                    for(var i = 0 ;i < data.info.length;i++ ){
                        countyData[i] = {value:data.info[i].town};
                    }
                    svar.setState({countyData:countyData});
                }
            }
        });
    },
    //查询省份
    queryProvince:function () {
        if($("#province").find(".pop-address-content-selectData").css('display')=='none'&&this.state.provinceData.length>0){
            $("#province").find(".pop-address-content-selectData").css('display','block');
            $("#city").find(".pop-address-content-selectData").css('display','none');
            $("#county").find(".pop-address-content-selectData").css('display','none');
            return false;
        }else if(this.state.provinceData.length>0){
            $("#province").find(".pop-address-content-selectData").css('display','none');
            return false;
        }
        this.queryAddress(1,"","");
        $("#province").find(".pop-address-content-selectData").css('display','block');
    },
    queryCity:function () {
        if($("#provinceid").next().html()=='选择省份'||$("#province").find(".pop-address-content-selectData").css('display')=='block'){
            return false;
        }
        if($("#city").find(".pop-address-content-selectData").css('display')=='block'){
            $("#city").find(".pop-address-content-selectData").css('display','none');
            return false;
        }
        this.queryAddress(2,$(".span-provinceid").html(),"");
        $("#city").find(".pop-address-content-selectData").css('display','block');
        $("#county").find(".pop-address-content-selectData").css('display','none');
    },
    queryCounty:function () {
        if($("#provinceid").next().html()=='选择省份'||$("#cityid").next().html()=='选择地区'||$("#city").find(".pop-address-content-selectData").css('display')=='block'
            ||$("#province").find(".pop-address-content-selectData").css('display')=='block'){
            return false;
        }
        if($("#county").find(".pop-address-content-selectData").css('display')=='block'){
            $("#county").find(".pop-address-content-selectData").css('display','none');
            return false;
        }
        this.queryAddress(3,"",$(".span-cityid").html());
        $("#county").find(".pop-address-content-selectData").css('display','block');
    },
    render:function () {
        return(
            <div className="pop-body-input address">
                <span className="pop-body-input-title address-span" style={{backgroundImage:schoolPopData.title=="新增学校"?"url(../img/icon/star.png)":"url()"}}>地区</span>
                <div className="pop-address-contents">
                    <div className="pop-address-content" id="province">
                        <input type="hidden" id="provinceid"/>
                        <span className="pop-address-content-default text-sub span-provinceid" title="" onClick={this.queryProvince}>选择省份</span>
                        <AddressData type="1" resultData={this.state.provinceData}/>
                    </div>
                    <div  id="city" className="pop-address-content">
                        <input type="hidden" id="cityid"/>
                        <span className="pop-address-content-default text-sub span-cityid" title="" onClick={this.queryCity}>选择地区</span>
                        <AddressData type="2"  resultData={this.state.cityData}/>
                    </div>
                    <div id="county" className="pop-address-content">
                        <input type="hidden" id="countyid" value="" data-dataType="Number" data-require="true" data-msg="地区不能为空"/>
                        <span className="pop-address-content-default text-sub span-countyid" title="" onClick={this.queryCounty}>选择县或街道</span>
                        <AddressData type="3"  resultData={this.state.countyData}/>
                    </div>
                </div>
            </div>
        );
    }
});
/**
 * 省市区组装下拉列表
 * @type {*}
 */
var AddressData = React.createClass({
    componentDidMount:function () {
        $('.pop-address-content').hover(function () {
        },function () {
            $('.pop-address-content-selectData').css('display','none');
        });
    },
    handleClick:function (e) {
        if($(e.target).attr("data-type")=="1"){
            $("#city").find(".pop-address-content-default").html('选择地区');
            $("#county").find(".pop-address-content-default").html('选择县或街道');
            this.setState({cityData:[],countyData:[]});
        }else if($(e.target).attr("data-type")=="2"){
            this.setState({countyData:[]});
            $("#county").find(".pop-address-content-default").html('选择县或街道');
        }
        $(e.target).parent().prev().html(e.target.innerHTML);
        $($(e.target).parent().prev()).attr("title",e.target.innerHTML);
        $(e.target).parent().prev().prev().val(e.target.innerHTML);
        $($(e.target).parent()).hide();
    },
    render:function () {
        var svar = this;
        var resultDATA=this.props.resultData.map(function (value,index) {
            return(
                <span onClick={svar.handleClick} data-type={svar.props.type} >{value.value}</span>
            );
        });
        return(
            <div className="pop-address-content-selectData">
                {resultDATA}
            </div>
        );
    }
});


//父组件
var Main = React.createClass({
    //组件初始状态
    getInitialState: function () {
        return {
            otherData:this.props.otherData,
            schoolData:this.props.schoolData,
            schoolPopData:this.props.schoolPopData,
            schoolDataList:this.props.schoolDataList,
            schoolDataAll:this.props.schoolDataAll,
            schoolDataType: false,//false全部学校、true和教育学校
            popSchoolDataType: false,//false全部学校、true和教育学校
        }
    },
    componentDidMount: function () {
        var svar = this;
        var param="param={";
        param = getJsonDataNotEmpty(param,"schoolname",$("#schoolname_search").val());
        param = getJsonDataNotEmpty(param,"pagecount",pagecount+"");
        param += "}";
        schoolData = [];
        suixun.ajax(serverUrl+'/schoolManage/querySchoolList.json',param,"get",function(data){
            setTimeout(function () {
                suixun.hideLoding();//隐藏加载中
            },500);
            if(data.code == 200){
                for(var i=0;i<data.info.queryresult.length;i++){
                    var obj=data.info.queryresult[i];
                    schoolData[i] = {id:obj.id,timeSettingid:obj.timeSettingid,province:obj.province,city:obj.city,town:obj.town,schoolname:obj.schoolname,dis:obj.dis,showtimesetting:obj.showtimesetting,address:obj.address,yijiaoid:obj.yijiaoid,starttime:obj.starttime,endtime:obj.endtime,price:obj.price,schooltype:obj.schooltype};
                }
                var pageRight = 0;
                if(data.info.totlepage > 1){
                    pageRight = 1
                }
                otherData = {maxHeight:height,currentpage:1,totlepage:data.info.totlepage,totlerows:data.info.totlerows,pageLeft:0,pageRight:pageRight,view:'school',batchNumber:'',upBatchNumber:''};
                currentpage = 1;totlepage = data.info.totlepage;//初始化的时候赋值：分页的当前页和总的页数
                svar.setState({schoolData:schoolData,otherData:otherData});
                svar.selectSchoolData();
            }
        });
        //绑定回车时间
        $(document).keypress(function(e) {
            var eCode = e.keyCode ? e.keyCode : e.which ? e.which : e.charCode;
            if (eCode == 13){
                if($(".enterEvent").is(":focus")){
                    svar.refs.getonClickQuery.onClickQuery(this.state.schoolDataType);
                }
            }
        });
    },
    /**
     * 获取表单数据
     */
    onClickSchool: function () {
        suixun.showLoding();//显示加载中
        otherData.view = "school";
        schoolData = [];
        var svar = this;
        var param="param={";
        param = getJsonDataNotEmpty(param,"schoolname",$("#schoolname_search").val());
        param = getJsonDataNotEmpty(param,"pagecount",pagecount+"");
        param += "}";
        suixun.ajax(serverUrl+'/schoolManage/querySchoolList.json',param,"get",function(data){
            suixun.hideLoding();//隐藏加载中
            if(data.code == 200){
                for(var i=0;i<data.info.queryresult.length;i++){
                    var obj=data.info.queryresult[i];
                    schoolData[i] = {id:obj.id,timeSettingid:obj.timeSettingid,province:obj.province,city:obj.city,town:obj.town,schoolname:obj.schoolname,dis:obj.dis,showtimesetting:obj.showtimesetting,address:obj.address,yijiaoid:obj.yijiaoid,starttime:obj.starttime,endtime:obj.endtime,price:obj.price,schooltype:obj.schooltype};
                }
                otherData = {maxHeight:height,currentpage:1,totlepage:data.info.totlepage,totlerows:data.info.totlerows,pageLeft:0,pageRight:1,view:'school',batchNumber:'',upBatchNumber:''};
                currentpage = 1;totlepage = data.info.totlepage;//初始化的时候赋值：分页的当前页和总的页数
                schoolDataList = schoolData;
                svar.setState({schoolData:schoolData,otherData:otherData});
                svar.selectSchoolData();
            }
        });
    },
    /**
     * 查询所有学校数据
     */
    selectSchoolData: function () {
        var svar = this;
        suixun.ajax(serverUrl+'/schoolManage/querySchool.json','',"get",function(data){
            suixun.hideLoding();//隐藏加载中
            schoolDataList = [];
            if(data.code == 200 ){
                for(var i=0;i<data.info.length;i++){
                    var obj=data.info[i];
                    schoolDataList[i] = {key:i,id:obj.id,schoolname:obj.schoolname};
                }
                schoolDataAll = schoolDataList;
                svar.setState({schoolDataList:schoolDataList,schoolDataAll:schoolDataAll});
            }else{
                svar.setState({schoolDataList:schoolDataList,schoolDataAll:schoolDataAll});
            }
        });
    },
    /**
     * 点击全部学校、和教育学校
     * @return {XML}
     */
    changgeSchoolDataType: function (type) {
        this.setState({schoolDataType:type});
        this.refs.getonClickQuery.onClickQuery(type);
    },
    /**
     * 新增、修改学校时，点击是否和教育学校
     * @return {XML}
     */
    changgePopSchoolDataType: function (type) {
        this.setState({popSchoolDataType:type});
    },
    render: function () {
        return (
            <div className="outside " >
                <div className="school tableManage-body">
                    <div className="header-menu">
                        <ul>
                            <li onClick={this.onClickSchool} className="select">学校</li>
                            <li><a href="../deviceInitManage/queryDeviceInitList.html">设备管理</a></li>
                            <li ><a href="../simInfoManage/querySimInfoList.html">SIM卡管理</a></li>
                            <li style={{display:"none"}}><a href="../packageManage/queryPackageList.html">设备套餐</a></li>
                            <li style={{display:"none"}}><a href="../devicePriceManage/queryDevicePriceList.html">设备零售价</a></li>
                            <li><a href="../deviceonReserve/queryonReserveList.html">区域储备量</a></li>
                            <li><a href="../attendance/attendanceMange.html">考勤机管理</a></li>
                        </ul>
                    </div>

                    <School selectSchoolData={this.selectSchoolData} schoolDataType={this.state.schoolDataType} popSchoolDataType={this.state.popSchoolDataType} changgeSchoolDataType={this.changgeSchoolDataType} changgePopSchoolDataType={this.changgePopSchoolDataType} ref="getonClickQuery" />
                </div>
            </div>
        );
    }
});
ReactDOM.render(
    <Main  otherData={otherData} schoolData={schoolData} schoolPopData={schoolPopData} schoolDataList={schoolDataList} schoolDataAll={schoolDataAll} />,
    document.getElementById('tableManage')
);
//删除时间区间
$(".time-father").on('click','.schoolDeleteTime',function () {
    var value = $(this).attr("data-value");
    if(value == 'id'){
        $(this).prev().val("");
        $(this).parent().prev().children().val("");
        $(this).parent().parent().hide();
    }else{
        $(this).parent().parent().remove();
    }

});
//鼠标移动函数 —— 下拉选择学校、姓名
$('.header-left .election-value,.header-right .election-value').hover(function(){
        if($(".drop-down").is(":hidden")){
            $(this).parent().find('.drop-down').slideDown();
            $(this).parent().hover(function(){},
                function(){
                    $(this).parent().find(".drop-down").slideUp();
                }
            );
        }
    },function(){}
);
//学校下拉列表
$("*").bind("click",function(e){
    var target = $(e.target);
    if(target.closest(".schoolList-value").length == 1){
        if("schoolname_search" == $(target.parent()).attr("data-inputId")){
            $("#"+$(target.parent()).attr("data-inputId")+"").val(target.html());
        }else{
            $("#"+$(target.parent()).attr("data-inputId")+"").val(target.html());
        }
        $(".schoolList").hide();
    }else{
        $(".schoolList").hide();
    }
});
$('.promoTimeInput').datetimepicker({
    format: "Y-m-d", //格式化日期
    timepicker: false, //显示时间选项
    todayButton: false, //关闭选择今天按钮
});